<template>
  <div class="comment-reply">
    <van-nav-bar
      fixed
      :title="
        comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'
      "
    >
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <comment-item :comment="comment" />
      <!-- /当前评论项 -->
      <!-- 评论列表 -->
      <van-cell title="全部评论" />
      <comment-list :source="comment.com_id" type="c" :list="commentList" />
      <!-- /评论列表 -->
    </div>
    <!-- 写评论 -->
    <div class="post-wrap">
      <van-button class="post-btn" size="small" round @click="isPostShow = true"
        >写评论</van-button
      >
    </div>
    <!-- /写评论 -->
    <!-- 写评论 弹出层 -->
    <van-popup v-model="isPostShow" position="bottom">
      <comment-post :target="comment.com_id" @postSuccess="onPostSuccess" />
    </van-popup>
    <!-- /写评论 弹出层 -->
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onPostSuccess(data) {
      console.log(data)
      this.isPostShow = false
      this.commentList.unshift(data.new_obj)
      this.comment.reply_count++
    }
  }
}
</script>

<style lang="less" scoped>
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  .post-btn {
    width: 60%;
  }
}
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow: auto;
}
</style>
